#ifndef CMAINVIEWWIDGET_H
#define CMAINVIEWWIDGET_H

/*
 MainViewWidget is a static area which contains fixed number of icons
 representing different functions of Qvernote app.

 Each icon is a MainViewItem class which contains Pixmap and String for a text
 */

#include <MWidget>
#include <MLayout>
#include <QGraphicsLinearLayout>
#include <QGraphicsGridLayout>
#include <MGridLayoutPolicy>
#include <MLinearLayoutPolicy>
#include <MFlowLayoutPolicy>
#include <MButton>
#include <MStylableWidget>
#include <mwidgetstyle.h>
#include "ui/MClickableImage.h"

class CMainViewItem : public MWidget
{
    Q_OBJECT

public:
    CMainViewItem(MWidget* parent = 0);
    CMainViewItem(QPixmap icon, QString label);
    CMainViewItem(QPixmap icon, char* label);

    void SetIcon(QPixmap& icon);
    void SetLabel(QString& label);

    void mousePressEvent ( QGraphicsSceneMouseEvent * event );
signals:
    void clicked();

protected:
    QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF());

private:
    void setupUi();

private:
    QPixmap         m_icon;
    QString         m_label;
    QGraphicsLinearLayout* m_layout;
    MImageWidget    m_widgetIcon;
    MLabel          m_widgetLabel;
};

/*
 Main view status bar is a bottom bar which can display either
 application status or sync progress bar
 */
#define STATUS_BAR_HEIGHT   38
class CMainViewStatusBar : public MWidget
{
public:
    CMainViewStatusBar(MWidget* parent = 0);
    CMainViewStatusBar(QString text, MWidget* parent = 0);

    void SetText(QString text);
    void SetProgress(QString text, int progress);
    void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

protected:
    QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF());

private:
    void setupUi();
    void DrawProgressBar( QPainter * painter, int m_progress);

private:
    MLayout* mainLayout;
    MLinearLayoutPolicy* landscapePolicy;
    MLinearLayoutPolicy* portraitPolicy;
    MLabel  m_lStatus;
    MLabel  m_pxmProgressBg;
    MImageWidget m_pxmProgressFill;
    QString m_text;
    int m_progress;
};

class CMainViewTitleWidget : public MWidget
{
public:
    CMainViewTitleWidget(MWidget* parent = 0);

protected:
    QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF());

private:
    void setupUi();

private:
    QGraphicsLinearLayout* mainLayout;
    MImageWidget    m_iwIcon;
    MClickableImage m_ciControl;
};

/*
 Main View widget - container of all above widgets
 to display the first page of evernote app
 */
class CMainViewWidget : public MWidget
{
    Q_OBJECT

public:
    CMainViewWidget(MWidget* parent = 0);
    void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

private:
    void setupUi();
    void setupVerticalPolicy();
    void setupHorizontalPolicy();

private:
    MLayout*    mainLayout;
    MGridLayoutPolicy*  verticalPolicy;
    MGridLayoutPolicy*  horizontalPolicy;
    //QGraphicsGridLayout*   mainLayout;
    CMainViewTitleWidget    m_titleWidget;
    CMainViewItem* m_iNewNote;
    CMainViewItem* m_iSnapshot;
    CMainViewItem* m_iNotebooks;
    CMainViewItem* m_iTags;
    CMainViewItem* m_iNotes;
    CMainViewItem* m_iSearches;
    CMainViewStatusBar* m_statusBar;
};

#endif // CMAINVIEWWIDGET_H
